package com.xysq.adapter;


import android.graphics.Bitmap;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.xysq.fragment.ImageFragment;
import com.xysq.util.CollectionUtil;

import java.util.ArrayList;
import java.util.List;

public class ImagePagerAdapter extends FragmentPagerAdapter {

    private List<String> mImageUrls;

    public ImagePagerAdapter(FragmentManager fm) {
        super(fm);
        mImageUrls = new ArrayList<>();
    }

    public void appendList(List<String> urls) {
        mImageUrls.addAll(urls);
    }

    @Override
    public Fragment getItem(int i) {
        if (CollectionUtil.isNullOrEmpty(mImageUrls)) {
            return null;
        }
        return ImageFragment.newInstance(mImageUrls.get(i));
    }

    @Override
    public int getCount() {
        return mImageUrls == null ? 0 : mImageUrls.size();
    }
}
